<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue3-005子组件ref</title>
    <script src="./vue3.js"></script>
</head>

<body>
    <div id="app">
        <child01 :ref="comp.homeView" title="首页" content="齐达内"></child01>
        <child01 :ref="comp.orderView" title="订单" content="贝克汉姆"></child01>
        <child01 :ref="comp.shoppingCartView" title="购物车"></child01>
        <child01 :ref="comp.usersettingView" title="个人设置"></child01>
    </div>
    <script>
        const { createApp, defineComponent, ref, onMounted, toRefs } = Vue

        let Child01 = defineComponent({
            template: `
                <h1>{{title}}</h1>
                <span>{{content}}</span>
            `,
            props: {
                title: {
                    type: String,
                    require: true
                },
                content: {
                    type: String,
                    default: '儿子'
                }
            },
            setup(props) {
                const { title, content } = toRefs(props)
                return {
                    title, content,
                    handle() {
                        alert('我是子组件：' + title)
                    }
                }
            }
        })

        createApp({
            components: { Child01 },
            setup() {

                let comp = {
                    homeView:           ref(),
                    orderView:          ref(),
                    shoppingCartView:   ref(),
                    usersettingView:    ref()
                }

                onMounted(_ => {
                    console.log(comp)
                })
                
                return {
                    comp
                }
            }
        }).mount("#app")
    </script>
</body>

</html>